home *** CD-ROM | disk | FTP | other *** search
/ Revista do CD-ROM 101 / CD-ROM 101.iso / compl / maya5ple / Install_MayaPLE5_English.exe / Maya / Data1.cab / expressions.mel < prev    next >
Encoding:
Text File  |  2003-07-17  |  17.7 KB  |  641 lines

  1. // Copyright (C) 1997-2002 Alias|Wavefront,
  2. // a division of Silicon Graphics Limited.
  3. //
  4. // The information in this file is provided for the exclusive use of the
  5. // licensees of Alias|Wavefront.  Such users have the right to use, modify,
  6. // and incorporate this code into other products for purposes authorized
  7. // by the Alias|Wavefront license agreement, without fee.
  8. //
  9. // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  10. // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  11. // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  12. // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  13. // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  14. // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  15. // PERFORMANCE OF THIS SOFTWARE.
  16. //
  17. //
  18. //  Alias|Wavefront Script File
  19. //  MODIFY THIS AT YOUR OWN RISK
  20. //
  21. //  ==================== expressions.mel ==========
  22. //
  23. //  SYNOPSIS
  24. //      Create and show a text dialog for creating and editing
  25. //        expressions
  26. //
  27. //  CONTENTS
  28. //        (The procs are in the file in the order listed here.)
  29. //
  30. //    Expression Editor Procedures:
  31. //
  32. //    EEisExpression            Check if a node is an expression node.
  33. //    EEdisplayExpression        Display an expression.
  34. //    EEexpressionCmd            Print the expression command just issued.
  35. //    EEapplyExpression        Create or edit the expression
  36. //    EErestoreExpression        Restore the current expression from the node.
  37. //  EEobjectListChanged        User selected a non-particle obj in the node list.
  38. //  EEexpressionListChanged    User selected a new non-particle expression in the
  39. //                            node list.
  40. //  EEonlyLaunchEditor        Launch a text editor for a regular expression.
  41. //
  42.  
  43.  
  44. // ******************************************************************
  45. //
  46. //                    PROCEDURES FOR REGULAR EXPRESSIONS
  47. //
  48. // ******************************************************************
  49.  
  50. //  ================ EEisExpression ================
  51. //
  52. //  SYNOPSIS
  53. //      Return whether the object is an expression node
  54. //
  55. global proc int EEisExpression(string $nodeName)
  56. {
  57.     string $expressions[] = `ls -type expression`;
  58.     int $i;
  59.     for ($i = 0; $i < size($expressions); $i++)
  60.     {
  61.         if ($nodeName == $expressions[$i])
  62.             return 1;
  63.     }
  64.     return 0;
  65.  
  66. }    // EEisExpression
  67.  
  68.  
  69. //  ================ EEresetExpressionName ================
  70. //
  71. //  SYNOPSIS
  72. //        Reset the expression name textfield. If in object
  73. //        mode, and the old name is not a particle node,
  74. //        unregister the old name for name changed messages; if the
  75. //        new name is not a particle node, register the new
  76. //        name for name changed messages.  
  77. //        (Don't register/unregister in expression mode, because the 
  78. //        selected expression is in the node list, and is already
  79. //        registered and shouldn't be unregistered.  Don't change
  80. //        particles, because the expression name is the node name,
  81. //        so it too is always in the node list, and is handled from
  82. //        there.
  83. //
  84. global proc EEresetExpressionName(string $name)
  85. {
  86.     global string $EEnodeMode;
  87.  
  88.     if ($EEnodeMode == "object")
  89.     {
  90.         // If in object mode, and there is a non-particle
  91.         // expression name in the expression name textfield,
  92.         // unregister it for name change messages.
  93.         //
  94.         string $oldExpressionName = `textField -q -tx EEexprNameT`;
  95.         if (size($oldExpressionName) && 
  96.             !EEisParticle($oldExpressionName))
  97.         {
  98.             expressionEditorListen -sln $oldExpressionName;
  99.         }
  100.     }
  101.     textField -e -tx $name EEexprNameT;
  102.     if(size($name) && $EEnodeMode == "object" && !EEisParticle($name))
  103.     {
  104.         expressionEditorListen -ln $name;
  105.     }
  106. }
  107.  
  108.  
  109. //  ================ EEdisplayExpression ================
  110. //
  111. //  SYNOPSIS
  112. //      Display the expression connected to the current
  113. //      object.attribute in the scrolled textfield, and
  114. //        put the name in the expression name textfield.
  115. //        And register it for node name changes, if in object
  116. //        mode (if it is selected in "Expression" mode, it will
  117. //        be registered already.  If there is already a non-particle
  118. //        expression in the textfield, and not in "Expression" mode,
  119. //        unregister it.
  120. //
  121. //
  122. global proc EEdisplayExpression(string $exprName)
  123. {
  124.     global int $EEdoLaunchTextEd;
  125.     global int $EEcurrentEditor;
  126.     global int $EEpExpressionInEditor;
  127.     global int $EEexpressionInEditor;
  128.     global string $EEorigExpressionName;
  129.     global string $EEcurrExpressionName;
  130.     global string $EEnodeMode;
  131.  
  132.     string $expressionName;
  133.     string $buffer[];
  134.  
  135.     tokenize($exprName, ".", $buffer);
  136.     $expressionName = $buffer[0];
  137.  
  138.     string $expression  = `expression -q -s $expressionName`;
  139.     string $defaultObj  = `expression -q -o $expressionName`;
  140.     int    $animatedVal = `expression -q -ae $expressionName`;
  141.     string $conversionPref = `expression -q -uc $expressionName`;
  142.  
  143.     // Set the data into the editor controls.
  144.     //
  145.     text -e -enable true EEexprNameLabel;
  146.     EEresetExpressionName($expressionName);
  147.     textField -e -enable true EEexprNameT;
  148.  
  149.     // The new expression name must be registered for getting
  150.     // name changed messages.
  151.     //
  152.     textFieldGrp -e -enable true EEdefNameT;
  153.  
  154.     // Set the name of the object.attribute connected to the expression
  155.     // in the "Selected Obj/Attr" field
  156.     //
  157.     string $objAttr[] = 
  158.         `listConnections -source false -d true -shapes true -plugs true  -scn true  $expressionName`;
  159.  
  160.     if (size($objAttr) > 0)
  161.         textFieldGrp -e -tx $objAttr[0] EEselNameT;
  162.     else
  163.         textFieldGrp -e -tx "" EEselNameT;
  164.  
  165.     scrollField -e -tx $expression EEmultiText;
  166.  
  167.     int $exprInEditor = EEexpressionIsInTextEditor($expressionName, 0);
  168.  
  169.     if ($EEcurrentEditor != 1 && $EEdoLaunchTextEd && $exprInEditor == -1)
  170.     {
  171.         if (size($objAttr) > 0)
  172.             EElaunchEditor($objAttr[0], $expression, $expressionName);
  173.         else
  174.             EElaunchEditor("", $expression, $expressionName);
  175.         scrollField -e -enable false EEmultiText;
  176.     }
  177.     else
  178.     {
  179.         if ($exprInEditor == -1)
  180.         {
  181.             $EEexpressionInEditor = -1;
  182.             scrollField -e -enable true EEmultiText;
  183.         }
  184.         else
  185.         {
  186.             $EEexpressionInEditor = $exprInEditor;
  187.             scrollField -e -enable false EEmultiText;
  188.         }
  189.     }
  190.     $EEpExpressionInEditor = -1;
  191.     $EEdoLaunchTextEd = 0;
  192.  
  193.     checkBox -e -v $animatedVal EEanimCBox;
  194.     if ($conversionPref == "none")
  195.         radioButtonGrp -e -sl 2 EEunitsRBG;
  196.     else if ($conversionPref == "angularOnly")
  197.         radioButtonGrp -e -sl 3 EEunitsRBG;
  198.     else
  199.         radioButtonGrp -e -sl 1 EEunitsRBG;
  200.  
  201.     // If there's a default object, set the textfield, otherwise clear it.
  202.     //
  203.     if (size($defaultObj) > 0)
  204.         textFieldGrp -e -tx $defaultObj EEdefNameT;
  205.     else
  206.         textFieldGrp -e -tx "" EEdefNameT;
  207.  
  208.     
  209.     $EEcurrExpressionName = $expressionName;
  210.     $EEorigExpressionName = $expressionName;
  211.  
  212.     EEsetEditMode("Editing Expression");
  213.  
  214. }    // EEdisplayExpression
  215.  
  216.  
  217. //  ================ EEexpressionCmd ================
  218. //
  219. //  SYNOPSIS
  220. //      Build the optional command args for the expression command
  221. //
  222. //
  223. global proc string EEexpressionCmd( int $isCreate,
  224.                                 string $theText,
  225.                                 int $anValue,
  226.                                 int $unitConvPref,
  227.                                 string $defaultObj,
  228.                                 string $newName)
  229. {
  230.     global string $EEorigExpressionName;
  231.     global int $EEeditedInEditor;
  232.  
  233.     string $theCommand;
  234.  
  235. //    The encodeString action was created by Rob T on Aug 19 to call
  236. //    Tstring::encodeEscapeSequences( true ) on the passed string
  237. //    variable.  This will allow quotes and other escapable characters
  238. //    to flow through evalEcho() smoothly.
  239. //
  240.     if ($isCreate)
  241.     {
  242.         $theCommand = ("expression -s \""+encodeString($theText)+"\" ");
  243.     }
  244.     else
  245.     {
  246.         $EEeditedInEditor = 1;
  247.         $theCommand = ("expression -e -s \""+encodeString($theText)+"\" ");
  248.     }
  249.  
  250.     if (size($defaultObj) > 0)
  251.         $theCommand = ($theCommand+" -o "+$defaultObj);
  252.     else
  253.         $theCommand = ($theCommand+" -o \"\"");
  254.  
  255.     if (size($newName) > 0)
  256.         $theCommand = ($theCommand+" -n \""+$newName+"\"");
  257.  
  258.     $theCommand = ($theCommand+" -ae "+$anValue);
  259.  
  260.     if ($unitConvPref == 3)
  261.         $theCommand = ($theCommand+" -uc angularOnly");
  262.     else if ($unitConvPref == 2)
  263.         $theCommand = ($theCommand+" -uc none");
  264.     else
  265.         $theCommand = ($theCommand+" -uc all ");
  266.  
  267.     if (!$isCreate)
  268.         $theCommand = ($theCommand+" "+$EEorigExpressionName);
  269.  
  270.     string $newExprName =  evalEcho($theCommand);
  271.  
  272.     $theCommand = ($theCommand+"\n");
  273.              
  274.     return $newExprName;
  275.     
  276. }    // EEexpressionCmd
  277.  
  278.  
  279.  
  280.  
  281. //  ================ EEapplyExpression ================
  282. //
  283. //  SYNOPSIS
  284. //      Create the expression in the editor and connect it to
  285. //        to the current selected attribute or
  286. //        replace its current expression with the newly edited one.
  287. //
  288. //
  289. global proc string EEapplyExpression(string $expression)
  290. {
  291.     global string $EEnodeMode;
  292.     global int $EEcreateMode;
  293.     global string $EEcurrExpressionName;
  294.     global string $EEorigExpressionName;
  295.  
  296.     string $newExprName, $currExprName;
  297.     string $selectedDefault, $defaultObj;
  298.  
  299.     // Get the current default object.attribute, expression
  300.     // node name, unit conversion preference, and animated value.
  301.     //
  302.     $defaultObj = `textFieldGrp -q -tx EEdefNameT`;
  303.  
  304.     $currExprName = `textField -q -tx EEexprNameT`;
  305.  
  306.     int $anFlagVal = `checkBox -q -v EEanimCBox`;
  307.  
  308.     int $unitConvPref = `radioButtonGrp -q -sl EEunitsRBG`;
  309.  
  310.     if (size($defaultObj) == 0)
  311.         $defaultObj = "";
  312.  
  313.     // If $currExprName != $currExpressionName, it means 
  314.     // the new name has not yet been processed or validated.
  315.     // (This can happen if the user does not press carriage
  316.     // return, and then selects "Apply", because there is
  317.     // no focus-out callback available in ELF.)
  318.     //
  319.     int $exprNameValid;
  320.     if (size($currExprName) > 0 && 
  321.         $currExprName != $EEcurrExpressionName)
  322.     {
  323.         if ($exprNameValid = EEcheckValidExprName($currExprName))
  324.             $EEcurrExpressionName = $currExprName;
  325.     }
  326.  
  327.     string $testExpr = ("\""+$expression+"\"");
  328.     if ($EEcreateMode)
  329.     {
  330.         // Create the new expression node.
  331.         //
  332.         if (size($currExprName) == 0 && 
  333.             size($EEcurrExpressionName) == 0)
  334.         {
  335.             $newExprName = 
  336.                 EEexpressionCmd(1, $expression, 
  337.                                 $anFlagVal, $unitConvPref, 
  338.                                 $defaultObj, "");
  339.         }
  340.         else
  341.         {
  342.             $newExprName = 
  343.                 EEexpressionCmd(1, $expression, 
  344.                                 $anFlagVal, $unitConvPref,
  345.                                 $defaultObj, $EEcurrExpressionName);
  346.         }
  347.  
  348.         // If error, error messages will have been sent from the
  349.         // command, so just do nothing, otherwise adjust controls.
  350.         //
  351.         if ($newExprName != "NULL")
  352.         {
  353.             if ($EEnodeMode == 1)
  354.                 textFieldGrp -e -enable true EEselNameT;
  355.             EEresetExpressionName($newExprName);
  356.  
  357.             EEsetEditMode("Editing Expression");
  358.  
  359.             $EEcurrExpressionName = $newExprName;
  360.             $EEorigExpressionName = $newExprName;
  361.  
  362.             // If in select-by-expression mode, update the list  of
  363.             // expressions.
  364.             //
  365.                if ($EEnodeMode == "expression")
  366.             {
  367.                 textScrollList -e -da EEnodeList;
  368.                 //
  369.                 // Commented out by Rob T. Since the name already gets
  370.                 // added by the NodeAdded callback.  Was getting added
  371.                 // twice.
  372.                 // EEaddNodeToList($EEcurrExpressionName);
  373.                 // Select the node.
  374.                 //
  375.                 EEselectNodeInList($EEcurrExpressionName);
  376.             }
  377.         }
  378.     }
  379.     else
  380.     {
  381.         // In edit mode; edit the expression
  382.         // If the expression name textfield is empty, print an
  383.         // error and do nothing
  384.         //
  385.         if (size($currExprName) == 0)
  386.         {
  387.             warning "Expression Editor: Name of expression being edited is missing.";
  388.             return "";
  389.         }
  390.     
  391.         // Edit the existing expression node.  Use $EEorigExpressionName,
  392.         // in case the user changed the name, since the edit has to be
  393.         // for the original name of the expression.
  394.         //
  395.         if ($EEcurrExpressionName == $EEorigExpressionName)
  396.         {
  397.             $newExprName =
  398.                 EEexpressionCmd(0, $expression, 
  399.                                 $anFlagVal,  $unitConvPref,
  400.                                 $defaultObj, "");
  401.         }
  402.         else
  403.         {
  404.             $newExprName =
  405.                 EEexpressionCmd(0, $expression, 
  406.                                 $anFlagVal, $unitConvPref,
  407.                                 $defaultObj, $EEcurrExpressionName);
  408.  
  409.             // If the user has changed the expression name, and is in
  410.             // select-by-expression mode, update the list with the new
  411.             // name.
  412.             //
  413.             if ($EEorigExpressionName != $EEcurrExpressionName)
  414.             {
  415.                    if ($EEnodeMode == "expression")
  416.                 {
  417.                     EEremoveNodeFromList($EEorigExpressionName, 0);
  418.  
  419.                     EEaddNodeToList($EEcurrExpressionName);
  420.                     // Select the node.
  421.                     //
  422.                     EEselectNodeInList($EEcurrExpressionName);
  423.  
  424.                 }
  425.                 $EEorigExpressionName = $EEcurrExpressionName;
  426.             }
  427.         }
  428.     }
  429.     return $newExprName;
  430.  
  431. }    // EEapplyExpression
  432.  
  433.  
  434.  
  435. //  ================ EErestoreExpression ================
  436. //
  437. //  SYNOPSIS
  438. //      Restore the current expression to the editor 
  439. //
  440. //
  441. global proc EErestoreExpression()
  442. {
  443.     global string $EEorigExpressionName;
  444.     global string $EEcurrExpressionName;
  445.  
  446.     // Get the expression, put it in the scrolled textfield
  447.     // and get its default obj and attr if there is one, and put in 
  448.     // the Default textfield
  449.     //
  450.     string $currDefObj, $currDefAttr;
  451.     string $currDefObjAttr, $expression;
  452.     string $defaultObj;
  453.  
  454.     $expression = `expression -q -s $EEorigExpressionName`;
  455.     scrollField -e -tx $expression EEmultiText;
  456.  
  457.     // Get the current and original default object and attribute
  458.     // of the expression.
  459.     //
  460.     $currDefObj = `textFieldGrp -q -tx EEdefNameT`;
  461.  
  462.     $defaultObj = `expression -q -o $EEorigExpressionName`;
  463.  
  464.     if($defaultObj != $currDefObj)
  465.     {
  466.         // If the defaultObj is not the same as the current one, 
  467.         // reset the textfield.
  468.         //
  469.         if (size($defaultObj) > 0)
  470.         {
  471.                textFieldGrp -e -tx $defaultObj EEdefNameT;
  472.         }
  473.         else
  474.         {
  475.             // There's no default object, so clear the textfield
  476.             //
  477.             textFieldGrp -e -tx "" EEdefNameT;
  478.         }
  479.     }
  480.  
  481. }    // EErestoreExpression
  482.  
  483.  
  484.  
  485.  
  486.  
  487.  
  488. //  ================ EEobjectListChanged ================
  489. //
  490. //  SYNOPSIS
  491. //     A non-particle node in the scrolled text list of nodes is selected.
  492. //
  493. global proc EEobjectListChanged(string $nodeName)
  494. {
  495.     global string $EEcurrSelectedNode;
  496.     global int $EEcurrentEditor;
  497.     global int $EEdoLaunchTextEd;
  498.  
  499.     string $objAttrName;
  500.  
  501.     // Here and below have to take into account that the user may
  502.     // have clicked (esp. double-clicked) on the node that is 
  503.     // currently already in the editor.  In that case, the only
  504.     // thing that needs to be done is launch a text editor, if the
  505.     // the user double-clicked.
  506.     //
  507.     if ($nodeName != $EEcurrSelectedNode)
  508.     {
  509.         // Object/attribute mode; user is selecting an object:
  510.  
  511.         // Clear all the controls in the editor, if a new node has
  512.         // been selected, and display the attrs of the new one.
  513.         //
  514.         EEclearAllControls();
  515.         EEresetNodeControls($nodeName);
  516.     }
  517.  
  518.     // If the user has double-clicked on the node, launch an editor.
  519.     //
  520.     if ($EEdoLaunchTextEd && $EEcurrentEditor != 1)
  521.     {
  522.         string $expression, $expressionName[];
  523.  
  524.         string $selectedAttr[] = `textScrollList -q -si EEattrList`;
  525.         string $objAttrName;
  526.         
  527.         if (size($selectedAttr) > 0)
  528.             $objAttrName = $nodeName + "." + $selectedAttr[0];
  529.         else
  530.             $objAttrName = $nodeName;
  531.  
  532.         $expressionName = 
  533.             `listConnections -s true -d false -t "expression"  -scn true  $objAttrName`;
  534.         int $exprInEditor = EEexpressionIsInTextEditor($expressionName[0], 0);
  535.  
  536.         if ($exprInEditor == -1)
  537.         {
  538.             if (size($selectedAttr) > 0 )
  539.             {
  540.                 $expression  = `expression -q -s $expressionName[0]`;
  541.                 EElaunchEditor($objAttrName, $expression, $expressionName[0]);
  542.             }
  543.             else
  544.             {
  545.                 EElaunchEditor($objAttrName, "", "");
  546.             }
  547.  
  548.             scrollField -e -enable false EEmultiText;
  549.         }
  550.     }
  551.  
  552. }    // EEobjectListChanged
  553.  
  554.  
  555. //  ================ EEexpressionListChanged ================
  556. //
  557. //  SYNOPSIS
  558. //     User has selected a new non-particle expression in the node list. 
  559. //
  560. global proc EEexpressionListChanged(string $expressionName)
  561. {
  562.     global string $EEcurrSelectedNode;
  563.     global int $EEcurrentEditor;
  564.     global int $EEdoLaunchTextEd;
  565.  
  566.     // Here and below have to take into account that the user may
  567.     // have clicked (esp. double-clicked) on the node that is 
  568.     // currently already in the editor.  In that case, the only
  569.     // thing that needs to be done is launch a text editor, if the
  570.     // the user double-clicked.
  571.     //
  572.     if ($expressionName != $EEcurrSelectedNode)
  573.     {
  574.         // Close the particles rules form.
  575.         //
  576.         EEswitchRulesForm(0);
  577.         EEdisplayExpression($expressionName);
  578.     }
  579.  
  580.     // If the user has double-clicked on the node, launch an editor.
  581.     //
  582.     int    $exprInEditor = EEexpressionIsInTextEditor($expressionName, 0);
  583.  
  584.     if ($EEdoLaunchTextEd && $EEcurrentEditor != 1 && $exprInEditor == -1)
  585.     {
  586.         string $expression;
  587.  
  588.         string $objAttr[] = `listConnections -source false -d true -shapes true -plugs true  -scn true  $expressionName`;
  589.         $expression  = `expression -q -s $expressionName`;
  590.         EElaunchEditor($objAttr[0], $expression, $expressionName);
  591.  
  592.         scrollField -e -enable false EEmultiText;
  593.     }
  594.  
  595. }    // EEexpressionListChanged
  596.  
  597.  
  598. //  ================ EEonlyLaunchEditor ================
  599. //
  600. //  SYNOPSIS
  601. //      Don't create and show the expression editor window; just
  602. //        launch a text editor.
  603. //
  604. global proc EEonlyLaunchEditor(string $nodeName, string $attrName)
  605. {
  606.     global string $EEcurrFiles[];
  607.     global string $EEcurrFileDefObj[];
  608.  
  609.     string $objAttrName;
  610.     
  611.     if (size($attrName) > 0)
  612.         $objAttrName = $nodeName + "." + $attrName;
  613.     else
  614.         $objAttrName = $nodeName;
  615.  
  616.     // Find the expression, if there is one that this node.attr is
  617.     // connected to.
  618.     //
  619.     string $exprName[] =
  620.         `listConnections -s true -d false -t "expression"  -scn true  $objAttrName`;
  621.  
  622.     // Set up default object here where we still have the object name,
  623.     // so the user doesn't have to type the node name.
  624.     //
  625.     int $fileNum = size($EEcurrFiles);
  626.     $EEcurrFileDefObj[$fileNum] = $nodeName;
  627.  
  628.     if (size($exprName[0]) == 0)
  629.     {
  630.         EElaunchEditor($objAttrName, "", "");
  631.     }
  632.     else
  633.     {
  634.         string $expression = `expression -q -s $exprName[0]`;
  635.         EElaunchEditor($objAttrName, $expression, $exprName[0]);
  636.     }
  637.  
  638. }    // EEonlyLaunchEditor
  639.  
  640.  
  641.